package attr

import (
	"context"
	"mall/services/product/rpc/internal/mapper"

	"mall/services/product/rpc/internal/svc"
	"mall/services/product/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelAttrValueLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelAttrValueLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelAttrValueLogic {
	return &DelAttrValueLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelAttrValueLogic) DelAttrValue(in *pb.DelAttrValueDTO) (*pb.EmptyObj, error) {
	// delete
	attrMapper := mapper.NewAttrValueMapper(l.ctx)
	err := attrMapper.DeleteCtx(l.svcCtx.DBEngin, in.AttrValueId)
	if err != nil {
		return nil, err
	}
	// return obj
	return &pb.EmptyObj{}, nil
}
